// pages/mine/mine.js
import store from "../../store/index";
import create from "../../utils1/create";

create.Page(store, {
  use: ['isToken', "infouser", "GroupInfo"],
  /**
   * 页面的初始数据
   */
  data: {
    number: 1,
    name: '谢浩',
    Hospitalphone: "17373023530",
    Hospital: '医林医疗',
  },

  Notviewed() {
    wx.navigateTo({
      url: '/pages/content/content?state=0'
    });
  },

  viewed() {
    wx.navigateTo({
      url: '/pages/content/content?state=1'
    });
  },

  phoneOn() {
    wx.showModal({
      title: '温馨提示',
      content: '跳转到电话拨打页面?',
      complete: (res) => {
        if (res.cancel) {

        }
        if (res.confirm) {
          const cmpTel = store.data.GroupInfo && store.data.GroupInfo.Cmp_Tel;
          if (cmpTel) {
            wx.makePhoneCall({
              phoneNumber: cmpTel, // 此号码仅用于测试
              success: (res) => {
                console.log(res);
                console.log("拨打电话成功！");
              },
              fail: (res) => {
                console.log(res);
                console.log("拨打电话失败！");
              }
            });
          } else {
            console.log("GroupInfo 或 Cmp_Tel 未定义");
          }

        }
      }
    })
  },

  domessage() {
    wx.navigateTo({
      url: '/pages/xguserpass/xguserpass'
    });
  },

  dogr() {
    wx.navigateTo({
      url: '/pages/infoemation/infoemation'
    });
  },

  doxgphone() {
    wx.navigateTo({
      url: '/pages/xgphone/xgphone?id=1'
    });
  },

  tclogin() {
    wx.showModal({
      title: '温馨提示',
      content: '您确定要退出登录吗?',
      success: (res) => {
        if (res.confirm) {
          console.log('用户点击了确定');
          wx.showToast({
            icon: 'loading',
            title: '退出登录中',
            mask: true
          });
          setTimeout(() => {
            wx.hideLoading();
            wx.removeStorageSync('token');
            wx.removeStorageSync('infouser');
            store.data.isToken = null;
            store.data.infouser = null;
            store.data.openid = null
            store.data.GroupInfo = null
            store.data.xxcount = null
          }, 1000);
          setTimeout(function () {
            wx.redirectTo({
              url: '/pages/login/login'
            });
          }, 2000)
        } else if (res.cancel) {
          console.log('用户点击了取消');
        }
      }
    });
  },

  doLogin() {
    wx.navigateTo({
      url: '/pages/login/login'
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('isToken', store.data.isToken);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    console.log('isToken', store.data.isToken);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    console.log('isToken', store.data.isToken);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
});